package cn.wolfcode.web.controller;


import cn.wolfcode.domain.MessageReply;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IMessageReplyService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/messageReply")
public class MessageReplyController {

    @Autowired
    private IMessageReplyService messageReplyService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        PageInfo<MessageReply> pageInfo = messageReplyService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "messageReply/list";
    }

    @RequestMapping("/delete")
    public String delete(Long id) {
        if (id != null) {
           messageReplyService.delete(id);
        }
        return "redirect:/messageReply/list";
    }

    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(MessageReply messageReply) {
        if (messageReply.getId() == null) {
            messageReplyService.save(messageReply);
        } else {
            messageReplyService.update(messageReply);
        }
        return "redirect:/messageReply/list";
    }

    @RequestMapping("/input")
    public String input(Long id, Model model) {
        if (id != null) {
            model.addAttribute("messageReply",messageReplyService.get(id));
        }
        return "messageReply/input";
    }
}
